# 作业 :CRMEB
# 1、用户分组
# 创建分组—查询分组（刚新增的分组）—删除分组
#
# 2、商品-商品分类
# 添加分类—查询分类（刚新增的分类）—删除分类
#
# 3、用户-用户管理
# 添加用户—查询用户（刚新增的用户）—删除用户
#
# 这里用户手机号用faker随机生成
#
# 4、客户—客服话术
# 添加话术—查询话术（刚新增的话术）—删除话术
#
# 生成测试报告，配置ini文件，注册标签smoke，按照标签名可以运行
import pytest,requests,allure
from faker import Faker


@allure.feature("CRMEB")
class Test_Crmeb():
    faker = Faker(locale='zh_cn')
    name = faker.name()
    project_url = "http://123.56.16.34:8899"
    @pytest.fixture(scope='function',autouse=True)
    def setup_teardown(self):
        response= requests.post(url = self.project_url + "/adminapi/login",json = {"account":"admin","pwd":"123456","imgcode":"a"})
        assert response.status_code == 200
        assert response.json()['msg'] =='ok'
        self.token = "Bearer " + str(response.json()['data']['token'])
        yield
        print("测试结束~")
    # @pytest.mark.smoke
    @allure.story("用户分组")
    def test_user_group(self):
        # 新增
        response = requests.post(url = self.project_url +"/adminapi/user/user_group/save.html",headers={"Authori-zation":self.token},json =
                      {"group_name":str(self.name) + "测试一下，你就知道"})
        assert response.status_code == 200
        assert response.json()['msg'] == "提交成功！"

        # 查找
        response1 = requests.get(url = self.project_url +"/adminapi/user/user_group/list?page=1&limit=15",
                                 headers={"Authori-zation":self.token})

        assert response1.status_code == 200
        for i in response1.json()['data']['list']:
            if i['group_name'] == str(self.name) + "测试一下，你就知道":
                self.id = i['id']

        # 删除
        response2 = requests.delete(url = self.project_url +"/adminapi/user/user_group/del/" +
                                          str(self.id),headers={"Authori-zation":self.token})
        assert response2.status_code == 200
        assert response2.json()['msg'] == '删除成功!'






